
var findStuInfo = toContextPath('/student/student_getInfo.action');
var findHomework = toContextPath('/student/homework_getAll.action');
var findHwItem = toContextPath('/student/homework_getById.action');
var loginHtml = toContextPath('/StuPages/login.html');

var homeworkState;
$(function(){	
	initPage();
});


function initPage() {
//	$('#hwContentDiv').hide();
	location.hash = '';
	$.getJSON(findStuInfo, function(data) {
		if (data.result && data.result.stuName){
			$('#stuName').text(data.result.stuName);
		} else {
			window.location.href = loginHtml;
		}
	});
	$.getJSON(findHomework, function(data) {
		if (data.result && data.result.length > 0){
			$.each(data.result, function(index, homework) {
				var item = '<tr ';
				if (homework.state == 0) {
					item += 'class="warning">';
					homeworkState = "Todo";
				} else if (homework.state == 1) {
					item += 'class="success">';
					homeworkState = "Done";
				}
				item = item + '<td>' + homework.hwCreateDate + '</td>'
				+ '<td>' + homework.hwDeadline + '</td>'
				+ '<td> <a onclick="clickA('+ homework.hwId+ ')">' + homework.hwName + '</a></td>'
				+ '<td>' + homework.teaName + '</td>'
				+ '<td ';
				if (homework.state == 0)
					item += 'style="color:red">' + homeworkState + '</td>'+ '</tr>';
				else if (homework.state == 1)
					item += 'style="color:green">' + homeworkState + '</td>'+ '</tr>';
				
				$('#homeworkList').append(item);
			});			
		}
	});	
}
function clickA(hwId) {
		$.getJSON(findHwItem, {hwId: hwId}, function(hwItem) {
			if (hwItem.success) {
				$('#hwContentTxt').text(hwItem.result.hwContent);
			//	$('#hwContentDiv').toggle();
			}
			
		});
}

//$("#userPwd").formValidator();